#pragma once
#include <assert.h>
#include <windows.h>
#include <commctrl.h>
#include "debug.h"
#include "err.h"
#include "C4047.h"

#define APP_WIDTH 780
#define APP_HEIGHT 480

HWND main_window;

#define user_message(msg) SetWindowText(static_bottom.handle, msg)
#define async(func) CreateThread(0, 0, func, 0, 0, 0)
#define decl_async_func(func) DWORD WINAPI func(void *dummy)
#define async_call(func) void async_##func(void) { async(func); }

struct child_window
{
	HWND handle;
	unsigned id;
} static_edit_hint, edit, listview, static_bottom;

enum DANMU_RECORD
{
	TIME, USERNAME, HASH, DATETIME, STYLE, FONT_SIZE, COLOUR, CONTENT,
	DANMU_RECORD_COUNT
};

struct danmu {
	char *dat[DANMU_RECORD_COUNT];
	unsigned hash_val, style_val, font_val, colour_val;
};

unsigned compare_index;

struct {
	struct danmu *head, *end;
	unsigned size;
	int *index, *index_end;
} danmu;

#define set_pos(control, x0, y0, x1, y1) \
	SetWindowPos(control, NULL, x0, y0, x1, y1, SWP_NOZORDER)

#define resize() do { \
	RECT rcClient; \
	GetClientRect(main_window, &rcClient); \
	resize_(rcClient.right, rcClient.bottom); \
} while (0)

extern struct column_data {
	char *label;
	unsigned label_width;
} column_datas[DANMU_RECORD_COUNT], *column_datas_end;